package com.gxa.controller;

import com.gxa.pojo.XsDd;
import com.gxa.service.XsDdService;
import com.gxa.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description: TOOD
 * @ClassName: XsRyController
 * @Author: ${陈柯宇}
 * Date: 2020/9/26 19:14
 * @Version: 1.0
 */
@Controller
@RequestMapping("/xsRy")
@Api(value = "执行人员销售详细操作的控制器",tags = "销售人员接口的Api")
@CrossOrigin
public class XsRyController {

    @Resource
    XsDdService xsDdService;

    /**
     * 销售人员分页数据
     *
     * @param map
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/selectAllByPersonPage", method = RequestMethod.POST)
    @ApiOperation(value = "查询销售人员列表分页接口", notes = "获取所有的销售人员数据列表", httpMethod = "post", response = String.class)
    public Map selectAllByPersonPage(@RequestBody(required = false) Map map) {
        JsonResult jsonResult = new JsonResult();
        try {
            String number = map.get("number").toString();
            String size = map.get("size").toString();
            Integer offset = (Integer.parseInt(number) - 1) * Integer.parseInt(size);
            Integer limit = Integer.parseInt(size);
            //List<XsDd> xsDds = xsDdService.selectAllByPersonPage(offset, limit);
            jsonResult.setCode("200");
            jsonResult.setMsg("检索成功");
            //jsonResult.setData(xsDds);
        } catch (Exception e) {
            jsonResult.setCode("501");
            jsonResult.setMsg("系统开小差了");
        }
        return jsonResult.getValues();
    }


    /**
     * 销售人员多参分页查询
     * @param map
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/selectByPersonLike",method = RequestMethod.POST)
    public Map<String,Object> selectByPersonLike(@RequestBody(required = false) Map<String,Object> map){
        JsonResult jsonResult=new JsonResult();
        if (map.get("startDate")!=null && !map.get("startDate").equals("") &&map.get("endDate")!=null && !map.get("endDate").equals("")){
        try {
            String number= map.get("number").toString();
            String size= map.get("size").toString();
            Integer offset =(Integer.parseInt(number)-1)*Integer.parseInt(size);
            Integer limit=Integer.parseInt(size);
            map.put("offset",offset);
            map.put("limit",limit);
            List<Map<String, Object>> mapList = xsDdService.selectByPersonLike(map);
            Integer count = xsDdService.selectByPersonLikeCount(map);
            jsonResult.put("count",count);
            jsonResult.setCode("200");
            jsonResult.setMsg("检索成功");
            jsonResult.setData(mapList);
        }catch (Exception e){
            e.printStackTrace();
            jsonResult.setCode("406");
            jsonResult.setMsg("系统开小差了");
        }}else {
            try {
                String number= map.get("number").toString();
                String size= map.get("size").toString();
                Integer offset =(Integer.parseInt(number)-1)*Integer.parseInt(size);
                Integer limit=Integer.parseInt(size);
                List<Map<String, Object>> mapList = xsDdService.selectAllByPersonPage(offset,limit);
                Integer count = xsDdService.selectByPersonLikeCount2();
                jsonResult.put("count",count);
                jsonResult.setCode("200");
                jsonResult.setMsg("检索成功");
                jsonResult.setData(mapList);
            }catch (Exception e){
                e.printStackTrace();
                jsonResult.setCode("406");
                jsonResult.setMsg("系统开小差了");
            }
        }
        return jsonResult.getValues();
    }

}




